package org.wyf.EveryPoint.common.service.impl;

import org.wyf.EveryPoint.common.entity.QueryRequest;

import org.wyf.EveryPoint.common.entity.DictCategory;
import org.wyf.EveryPoint.common.mapper.DictCategoryMapper;
import org.wyf.EveryPoint.common.service.IDictCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * 字典类别表 Service实现
 *
 * @author wyf
 * @date 2021-04-21 15:46:07
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class DictCategoryServiceImpl extends ServiceImpl<DictCategoryMapper, DictCategory> implements IDictCategoryService {

    private final DictCategoryMapper dictCategoryMapper;

    @Override
    public IPage<DictCategory> findDictCategorys(QueryRequest request, DictCategory dictCategory) {
        LambdaQueryWrapper<DictCategory> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<DictCategory> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<DictCategory> findDictCategorys(DictCategory dictCategory) {
	    LambdaQueryWrapper<DictCategory> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createDictCategory(DictCategory dictCategory) {
        this.save(dictCategory);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateDictCategory(DictCategory dictCategory) {
        this.saveOrUpdate(dictCategory);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteDictCategory(DictCategory dictCategory) {
        LambdaQueryWrapper<DictCategory> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}
}
